//
//  WYCmyCardCotroller.m
//  掌上还
//
//  Created by 王晓民 on 2018/1/13.
//  Copyright © 2018年 中企互联. All rights reserved.
//

#import "WYCmyCardCotroller.h"
#import "WYCbankViewController.h"
@interface WYCmyCardCotroller ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSArray *bankimgArr;
@property(nonatomic,strong)NSArray *banktitArr;
@property(nonatomic,strong)UILabel  *bankLb;
@end

@implementation WYCmyCardCotroller

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNav];
    _bankimgArr = @[@"bank_xy", @"bank_pf", @"bank_ms", @"bank_jt",@"bank_gd",@"bank_gd",@"bank_pa",@"bank_gs",@"bank_ms"];
    _banktitArr = @[@"兴业银行", @"浦发银行", @"民生银行", @"交通银行",@"光大银行金普卡",@"光大高端白金卡",@"平安银行",@"工商银行",@"民生银行学生卡"];
    self.view.backgroundColor = WYCGlobalBg;
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    
    layout.headerReferenceSize = CGSizeMake(self.view.frame.size.width, 5);
    layout.footerReferenceSize = CGSizeMake(self.view.frame.size.width, 5);
    
    //该方法也可以设置itemSize
    layout.itemSize =CGSizeMake(ScreenWidth/3-10, 150);
    //    layout.minimumLineSpacing = 10;
    //    layout.minimumInteritemSpacing =10;
    
    UICollectionView * mainCollectionView= [[UICollectionView alloc] initWithFrame:CGRectMake(5, NavHeight, ScreenWidth-10, ScreenHeight) collectionViewLayout:layout];
    [self.view addSubview:mainCollectionView];
    mainCollectionView.backgroundColor = WYCGlobalBg;
    //3.注册collectionViewCell
    //注意，此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为 cellId
    [mainCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellId"];
    
    //注册headerView  此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致  均为reusableView
    [mainCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView"];
    
    //4.设置代理
    mainCollectionView.delegate = self;
    mainCollectionView.dataSource = self;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//Nav字体颜色+ 背景
- (void)setupNav {
    self.navigationItem.title = @"办卡";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setBarTintColor:wycMain];
}
//设置分区数（必须实现）
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

//设置每个分区的item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _banktitArr.count;
}

//设置返回每个item的属性必须实现）
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    
    UIImageView  *bankBg = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, ScreenWidth/3-40, ScreenWidth/3-40)];
    bankBg.image =[UIImage imageNamed:[_bankimgArr objectAtIndex:indexPath.row]];
    [cell.contentView addSubview:bankBg];
    
    UIView  *line  = [[UIView alloc]initWithFrame:CGRectMake(5, bankBg.frame.size.height+bankBg.frame.origin.y+10, ScreenWidth/3-20, 1)];
    line.backgroundColor = WYCGlobalBg;
    [cell.contentView addSubview:line];
    _bankLb = [[UILabel alloc]initWithFrame:CGRectMake(0, bankBg.frame.size.height+bankBg.frame.origin.y+15, ScreenWidth/3-10, 30 )];
    _bankLb.text = [_banktitArr objectAtIndex:indexPath.row];
    _bankLb.textColor = [UIColor grayColor];
    _bankLb.textAlignment =NSTextAlignmentCenter;
    _bankLb.font = [UIFont systemFontOfSize:13];
    [cell.contentView addSubview:_bankLb];
    
    return cell;
}



-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row ==0)
    {
//    NSString *rowString = [self.banktitArr objectAtIndex:[indexPath row]];
    WYCbankViewController  *bankView = [[WYCbankViewController alloc]init];
//    bankView.bankTitle = rowString;
//    bankView.number = indexPath.row;
    [self.navigationController pushViewController:bankView animated:YES];
    }
}







@end
